/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GraphicComponent;

import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.GrayFilter;
import javax.swing.ImageIcon;
import javax.swing.JButton;

/**
 *
 * @author Hoang
 */
public class MediaControlBoardPanel extends javax.swing.JPanel {

    IMediaPanelContainer container;
    boolean isRunning = false;
    boolean isplay = false;
    File directory = new File("");
    String urlPlay = directory.getAbsolutePath()+"\\src\\icon\\001.png";
    String urlPlayD = directory.getAbsolutePath()+"\\src\\icon\\001d.png";
    String urlPlayG = directory.getAbsolutePath()+"\\src\\icon\\001g.png";
    
    String urlBack = directory.getAbsolutePath()+"\\src\\icon\\back.png";
    String urlForward = directory.getAbsolutePath()+"\\src\\icon\\for.png";
    
    String urlStopD = directory.getAbsolutePath()+"\\src\\icon\\stop1.png";
    String urlStopG = directory.getAbsolutePath()+"\\src\\icon\\stop2.png";
    
    String urlPause = directory.getAbsolutePath()+"\\src\\icon\\pause3.png";
    String urlPauseD = directory.getAbsolutePath()+"\\src\\icon\\pause1.png";
    String urlPauseG = directory.getAbsolutePath()+"\\src\\icon\\pause2.jpg";
    


    public void setContainer(IMediaPanelContainer con){
        container = con;
    }
    /**
     * Creates new form MediaControlBoardPanel
     */
    public MediaControlBoardPanel() {
        initComponents();
        initIconButton();
    }
    long startTime, endTime;
    public void setTimePeriod(long s, long e){
        startTime = s;
        endTime = e;
        
        //jStartTimeLabel.setText(String.valueOf(s));
        //jStartTimeLabel.setText(String.valueOf(e));
    }
    public void setTimeValue(long v){
        try{
            jSlider1.setValue((int)v * 100 / (int)(startTime - endTime));
        }
        catch(Exception ex){}
    }
    public void reset(){
        
    }
void initIconButton()
{
    jButtonPlay.setIcon(new javax.swing.ImageIcon(urlPlay));
    jButtonPlay.setRolloverIcon(new javax.swing.ImageIcon(urlPlayG));
    
    jButtonBackward.setIcon(new javax.swing.ImageIcon(urlBack));
    jButtonForward.setIcon(new javax.swing.ImageIcon(urlForward));
    
    jButtonStop.setIcon(new javax.swing.ImageIcon(urlStopD));
    jButtonStop.setRolloverIcon(new javax.swing.ImageIcon(urlStopG));
}
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton4 = new javax.swing.JButton();
        jButtonPlay = new RoundButton();
        jButtonStop = new javax.swing.JButton();
        jSlider1 = new javax.swing.JSlider();
        jButtonBackward = new javax.swing.JButton();
        jButtonForward = new javax.swing.JButton();
        jEndTimeLabel = new javax.swing.JLabel();
        jCurrentTimeLabel = new javax.swing.JLabel();

        jButton4.setText("jButton3");

        setBackground(new java.awt.Color(255, 255, 255));
        setPreferredSize(new java.awt.Dimension(1000, 180));

        jButtonPlay.setBorder(null);
        jButtonPlay.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jButtonPlayMouseReleased(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jButtonPlayMousePressed(evt);
            }
        });

        jButtonStop.setBorder(null);
        jButtonStop.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jButtonStopMousePressed(evt);
            }
        });
        jButtonStop.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonStopActionPerformed(evt);
            }
        });

        jSlider1.setPreferredSize(new java.awt.Dimension(200, 20));
        jSlider1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jSlider1MouseReleased(evt);
            }
        });

        jButtonBackward.setBorder(null);
        jButtonBackward.setMaximumSize(new java.awt.Dimension(25, 9));
        jButtonBackward.setMinimumSize(new java.awt.Dimension(25, 9));
        jButtonBackward.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jButtonBackwardMouseReleased(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jButtonBackwardMousePressed(evt);
            }
        });
        jButtonBackward.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBackwardActionPerformed(evt);
            }
        });

        jButtonForward.setBorder(null);
        jButtonForward.setMaximumSize(new java.awt.Dimension(25, 9));
        jButtonForward.setMinimumSize(new java.awt.Dimension(25, 9));
        jButtonForward.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jButtonForwardMouseReleased(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jButtonForwardMousePressed(evt);
            }
        });
        jButtonForward.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonForwardActionPerformed(evt);
            }
        });

        jEndTimeLabel.setText("jLabel3");

        jCurrentTimeLabel.setText("jLabel1");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jCurrentTimeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButtonPlay, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonBackward, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonForward, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonStop, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jEndTimeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jSlider1, javax.swing.GroupLayout.DEFAULT_SIZE, 920, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(99, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSlider1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCurrentTimeLabel, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonBackward, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonForward, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonStop, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jEndTimeLabel, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButtonPlay, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonPlayMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonPlayMousePressed
        // TODO add your handling code here:
        ImageIcon icon = new ImageIcon(urlPlayD);
        ImageIcon iconP = new ImageIcon(urlPauseD);
//        ImageIcon grayIcon = new ImageIcon(GrayFilter.createDisabledImage(icon.getImage()));
        
        if(isplay == true)
        {
            jButtonPlay.setIcon(iconP);
            
        }else
            jButtonPlay.setIcon(icon);
    }//GEN-LAST:event_jButtonPlayMousePressed

    private void jButtonPlayMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonPlayMouseReleased
        // TODO add your handling code here:
        ImageIcon icon = new ImageIcon(urlPlay);
        ImageIcon iconR = new ImageIcon(urlPlayG);
//        jButtonPlay.setIcon(icon);
        ImageIcon pIcon = new ImageIcon(urlPause);
        ImageIcon pIconR = new ImageIcon(urlPauseG);
        boolean b = false;
        if(isplay == true)
        {
            if(container != null)
                b = container.Pause();
            if(b){
                jButtonPlay.setIcon(icon);
                jButtonPlay.setRolloverIcon(iconR);
            }
            else{
                jButtonPlay.setIcon(pIcon);
                jButtonPlay.setRolloverIcon(pIconR);
            }
            
            isplay = false;
            
        }
        else
        {
            if(container != null)
                b = container.Play();
            if(b){
                jButtonPlay.setIcon(pIcon);
                jButtonPlay.setRolloverIcon(pIconR);
            }
            else{
                jButtonPlay.setIcon(icon);
                jButtonPlay.setRolloverIcon(iconR);
            }
            
            isplay = true;
        }
        System.out.println(isplay == true ? "playing" : "pause");

    }//GEN-LAST:event_jButtonPlayMouseReleased

    private void jButtonBackwardMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonBackwardMousePressed
        // TODO add your handling code here:
        ImageIcon icon = new ImageIcon(urlBack);
        ImageIcon grayIcon = new ImageIcon(GrayFilter.createDisabledImage(icon.getImage()));
        jButtonBackward.setIcon(grayIcon);
    }//GEN-LAST:event_jButtonBackwardMousePressed

    private void jButtonBackwardMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonBackwardMouseReleased
        // TODO add your handling code here:
        ImageIcon icon = new ImageIcon(urlBack);
        jButtonBackward.setIcon(icon);
    }//GEN-LAST:event_jButtonBackwardMouseReleased

    private void jButtonForwardMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonForwardMousePressed
        // TODO add your handling code here:
        ImageIcon icon = new ImageIcon(urlForward);
        ImageIcon grayIcon = new ImageIcon(GrayFilter.createDisabledImage(icon.getImage()));
        jButtonForward.setIcon(grayIcon);
    }//GEN-LAST:event_jButtonForwardMousePressed

    private void jButtonForwardMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonForwardMouseReleased
        // TODO add your handling code here:
        ImageIcon icon = new ImageIcon(urlForward);
        jButtonForward.setIcon(icon);
    }//GEN-LAST:event_jButtonForwardMouseReleased

    private void jButtonStopMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonStopMousePressed
        // TODO add your handling code here:
        ImageIcon icon = new ImageIcon(urlStopD);
//        ImageIcon grayIcon = new ImageIcon(GrayFilter.createDisabledImage(icon.getImage()));
        jButtonStop.setIcon(icon);
    }//GEN-LAST:event_jButtonStopMousePressed

    private void jButtonForwardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonForwardActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButtonForwardActionPerformed

    private void jButtonStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonStopActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButtonStopActionPerformed

    private void jButtonBackwardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBackwardActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButtonBackwardActionPerformed

    private void jSlider1MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jSlider1MouseReleased
        // TODO add your handling code here:
        javax.swing.JSlider js = (javax.swing.JSlider)evt.getSource();
        System.out.println(js.getValue());
    }//GEN-LAST:event_jSlider1MouseReleased

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButtonBackward;
    private javax.swing.JButton jButtonForward;
    private javax.swing.JButton jButtonPlay;
    private javax.swing.JButton jButtonStop;
    private javax.swing.JLabel jCurrentTimeLabel;
    private javax.swing.JLabel jEndTimeLabel;
    private javax.swing.JSlider jSlider1;
    // End of variables declaration//GEN-END:variables
}
